home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Misc / emu / Wzonka-Lad.lha / Wzonka-Lad / src / screen_draw_new_II.s < prev    next >
Text File  |  1999-05-08  |  34KB  |  1,328 lines

  1.  
  2. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  3. ;        screen draw - the next generation edition ;)
  4. ;
  5. ;        what are the main differences between this and the older
  6. ;        generation screen_draw_x.S? here they come...
  7. ;
  8. ;        all the things are rendered directly into chip ram.
  9. ;        no memory areas are allocated for masking or something
  10. ;        like that. here's the dimensions for the chip ram area:
  11. ;        16+160+16 = 192 (32 bit) pixels wide and
  12. ;        16+144+16 = 176 (16 bit) pixels height planar data area.
  13. ;
  14. ;        first the background is copied to the chip area.
  15. ;        start x = 8, start y = 16.
  16. ;        then comes the h/w window.
  17. ;        start x = 8, start y = 16 (remember to add the scroll pixels!).
  18. ;        then come the sprites.
  19. ;        start x = 0, start y = 0 (remember to add the scroll pixels!).
  20. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  21.  
  22. screen_draw:    tst.b    old_render            ;aga?
  23.         beq.w    aga_screen_draw            ;yes.
  24.  
  25.         move.l    a2,a6                ;a6 = the fixed 16bit
  26.         add.l    #$ff40,a6            ;a6 = lcd control.
  27.         moveq.l    #0,d7
  28.         move.b    (a6),d7                ;d7 = lcd control byte.
  29.         btst    #7,d7                ;lcd operation?
  30.         beq.s    no_screen_draw            ;no. clear and quit.
  31.         move.l    d7,lcd_control            ;store the byte.
  32.  
  33.         bsr.w    push_z80
  34.  
  35.         bsr.w    screen_draw_bg            ;do the background copy.
  36.         bsr.w    screen_draw_wi            ;do the window copy.
  37.         bsr.w    screen_sprites            ;do them!
  38.         bsr.w    swap_lists_nor            ;swap the sprite y lists.
  39.         bsr.w    screen_draw_pl            ;all h/w effects are done!
  40.         bsr.w    update_bg_pal            ;output the palette.
  41.  
  42.         bsr.w    pull_z80
  43.  
  44. no_screen_draw:    rts                    ;exit.
  45.  
  46. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  47. ;        empty screen
  48. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  49.  
  50. screen_empty:    tst.b    old_render            ;aga?
  51.         beq.s    aga_empty            ;yes.
  52.  
  53.         move.l    bitmap_spc,a0
  54.         move.l    bitmap_bg,a1
  55.  
  56.         moveq.l    #0,d1
  57.         tst.b    old_refresh            ;mode 144/144?
  58.         bne.s    e_normal            ;no.
  59.         move.w    #160/32*144*2-1,d0        ;yes.
  60.         bra.s    empty_all
  61. e_normal:    move.w    #gb_screen_x/32*gb_screen_y*2-1,d0
  62. empty_all:    move.l    d1,(a0)+
  63.         move.l    d1,(a1)+
  64.         dbra    d0,empty_all
  65.         rts
  66.  
  67. aga_empty:    move.l    aga_map_I,a0
  68.         move.l    aga_map_II,a1
  69.         move.w    #40*256*8/4/4-1,d0
  70.         moveq.l    #0,d1
  71. aga_empty_all:    move.l    d1,(a0)+
  72.         move.l    d1,(a0)+
  73.         move.l    d1,(a0)+
  74.         move.l    d1,(a0)+
  75.         move.l    d1,(a1)+
  76.         move.l    d1,(a1)+
  77.         move.l    d1,(a1)+
  78.         move.l    d1,(a1)+
  79.         dbra    d0,aga_empty_all
  80.         rts
  81.  
  82. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  83. ;        swap the speedup buffers
  84. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  85.  
  86. swap_lists_nor:    cmp.b    #2,old_render            ;window?
  87.         beq.s    sprs_xx_done            ;yes. no buffer changes.
  88.  
  89.         move.l    aga_sprs_inactive,d7
  90.         cmp.l    aga_sprs_cI,d7
  91.         beq.s    sprs_II_in_nor
  92. sprs_I_in_nor:    move.l    aga_sprs_cI,aga_sprs_inactive
  93.         move.l    aga_sprs_cxI,aga_sprs_inactive_x
  94. sprs_xx_done:    rts
  95. sprs_II_in_nor:    move.l    aga_sprs_cII,aga_sprs_inactive
  96.         move.l    aga_sprs_cxII,aga_sprs_inactive_x
  97.         rts
  98.  
  99. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  100. ;        recreate and update the background palette
  101. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  102.  
  103. update_bg_pal:    tst.b    old_render            ;window/screen?
  104.         beq.w    no_upd_col            ;nope
  105.  
  106.         move.l    gb_memory,a0
  107.         add.l    #$ff47,a0            ;bgrdpal (background palette).
  108.         moveq.l    #0,d0
  109.         move.b    (a0),d0                ;d0 = palette byte.
  110.  
  111.         cmp.b    #2,old_render
  112.         beq.w    window_colour_update
  113.  
  114.         lea    gb_pale,a1            ;a1 = output palette.
  115.         lea    gameboy_colours,a2
  116.         tst.l    cartridge
  117.         bne.s    update_bg_ok
  118.  
  119.         move.b    #%11100100,d0            ;default palette position.
  120.  
  121. update_bg_ok:    moveq.l    #4-1,d7
  122.  
  123. update_bg_clx:    move.l    d0,d1
  124.         and.b    #%11,d1                ;colour (0-3).
  125.         move.l    (a2,d1.l*4),d1
  126.         move.l    d1,d2
  127.         clr.w    d1
  128.         lsl.l    #8,d1
  129.         move.l    d1,(a1)+
  130.         move.l    d2,d1
  131.         and.l    #$0000ff00,d1
  132.         swap    d1
  133.         move.l    d1,(a1)+
  134.         and.l    #$000000ff,d2
  135.         ror.l    #8,d2
  136.         move.l    d2,(a1)+            ;colour (0-3) loaded.
  137.         lsr.b    #2,d0
  138.         dbra    d7,update_bg_clx
  139.  
  140.         add.l    #4*4,a2                ;to sprite palette.
  141.         moveq.l    #4-1,d0
  142. move_spr_clrs:    move.l    (a2)+,d1
  143.         move.l    d1,d2
  144.         move.l    d1,d3
  145.         clr.w    d1
  146.         lsl.l    #8,d1
  147.         move.l    d1,(a1)+
  148.         and.l    #$0000ff00,d2
  149.         swap    d2
  150.         move.l    d2,(a1)+
  151.         and.l    #$000000ff,d3
  152.         ror.l    #8,d3
  153.         move.l    d3,(a1)+            ;colour (0-3) loaded.
  154.         move.l    d1,(a1)+
  155.         move.l    d2,(a1)+
  156.         move.l    d3,(a1)+
  157.         move.l    d1,(a1)+
  158.         move.l    d2,(a1)+
  159.         move.l    d3,(a1)+
  160.         dbra    d0,move_spr_clrs
  161.  
  162.         move.l    gb_screen_ptr,d0        ;the screen.
  163.         beq.s    no_upd_col
  164.         move.l    graphics_base,a6
  165.         move.l    d0,a0
  166.         lea    sc_ViewPort(a0),a0        ;the view port.
  167.         lea    gb_pal,a1            ;the background palette.
  168.         jsr    LoadRGB32(a6)            ;load in the new colours.
  169. no_upd_col:    rts                    ;exit the palette part.
  170.  
  171. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  172. ;        update window "palette"
  173. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  174.  
  175. window_colour_update:
  176.         move.b    back_ground_colour_byte,d5
  177.         cmp.b    d5,d0
  178.         beq.s    window_colour_update_exit
  179.         move.b    d0,back_ground_colour_byte
  180.         eor.b    d0,d5
  181.  
  182.         lea    pen_list,a2
  183.         lea    gameboy_colours_conversion_table,a1
  184.         moveq.l    #4-1,d7
  185.  
  186. update_window_clx:
  187.         move.l    d0,d1
  188.         and.b    #%11,d1
  189.         move.b    (a2,d1.l),(a1)+
  190.         lsr.b    #2,d0
  191.         dbra    d7,update_window_clx
  192.  
  193.         lea    gameboy_colours_conversion_table,a0
  194.         move.l    pen_conversion_table,a1
  195.         moveq.l    #0,d3
  196.         moveq.l    #0,d7
  197.  
  198.         move.b    d5,d0
  199.         and.b    #%11,d0
  200.         beq.s    no_colour_change_0
  201.         bsr.b    do_conversion_table_x
  202.  
  203. no_colour_change_0:
  204.         move.b    d5,d0
  205.         and.b    #%1100,d0
  206.         beq.s    no_colour_change_1
  207.         move.b    #1,d7
  208.         bsr.b    do_conversion_table_x
  209.  
  210. no_colour_change_1:
  211.         move.b    d5,d0
  212.         and.b    #%110000,d0
  213.         beq.s    no_colour_change_2
  214.         move.b    #2,d7
  215.         bsr.b    do_conversion_table_x
  216.  
  217. no_colour_change_2:
  218.         move.b    d5,d0
  219.         and.b    #%11000000,d0
  220.         beq.s    window_colour_update_exit
  221.         move.b    #3,d7
  222.         bsr.b    do_conversion_table_x
  223.  
  224. window_colour_update_exit:
  225.         rts
  226.  
  227. do_conversion_table_x:
  228.         move.b    (a0,d7.l),d4
  229.         moveq.l    #16-1,d1
  230.         move.b    d7,d6
  231.         lsl.w    #8,d4
  232.         lsl.w    #8,d6
  233.         lea    16(a0),a2
  234. do_conversion_table_copy_x:
  235.         move.w    d4,d2
  236.         move.w    d6,d3
  237.         move.b    -(a2),d2
  238.         move.b    d1,d3
  239.         move.w    d2,(a1,d3.l*2)
  240.         ror.w    #8,d2
  241.         ror.w    #8,d3
  242.         move.w    d2,(a1,d3.l*2)
  243.         dbra    d1,do_conversion_table_copy_x
  244.         rts
  245.  
  246. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  247. ;        execute the background copying
  248. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  249.  
  250. screen_draw_bg:    move.l    d7,d0                ;d0 = lcd control byte.
  251.         btst    #0,d0                ;background display?
  252.         beq.w    no_upd_col            ;no. quit.
  253.  
  254.         move.l    a2,a1
  255.         add.l    #$ff42,a1            ;a1 = lcd control.
  256.         moveq.l    #0,d2
  257.         move.b    (a1)+,d2            ;d2 = bg scroll y.
  258.         moveq.l    #0,d3
  259.         move.b    (a1),d3                ;d3 = bg scroll x.
  260.  
  261.         move.l    d0,d1                ;d1 = the control byte.
  262.         and.b    #%1000,d0            ;d0 = background tiles.
  263.         lsl.w    #7,d0                ;0/1 * 1024.
  264.         move.l    a2,a1
  265.         add.l    #$9800,a1            ;tile position.
  266.         add.l    d0,a1                ;selected position.
  267.                             ;a1 = input tiles.
  268.         and.b    #%10000,d1            ;d1 = background tile
  269.         move.l    d1,d7                ;datas. 0/1 * 2048.
  270.         lsl.b    #3,d1                ;d7 = tile adder (signed/
  271.         bchg    #7,d1                ;unsigned).
  272.         move.l    d1,tile_adder
  273.         lsl.w    #7,d7
  274.         add.l    #$8800,a2            ;tile data position.
  275.         sub.l    d7,a2                ;selected position.
  276.                             ;a2 = input tile datas.
  277.         move.l    a2,gb_tiles
  278.  
  279. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  280. ;        copy background data
  281. ;        INPUT:
  282. ;        d1    = tile adder.
  283. ;        d2    = background scroll y.
  284. ;        d3    = background scroll x.
  285. ;        a1    = tiles.
  286. ;        a2    = tile datas.
  287. ;        NOTE:
  288. ;        output plane information: 192x176 (+4, +4). background tiles
  289. ;        will be positioned starting at +1, +2.
  290. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  291.  
  292.         move.l    d2,d4
  293.         move.l    d3,d5
  294.         lsr.b    #3,d2                ;d2 = number of rows
  295.                             ;to be skipped.
  296.         lsl.w    #5,d2                ;d2 = d2 * 32 (start y).
  297.         lsr.b    #3,d3                ;d3 = x start.
  298.  
  299.         and.b    #%111,d5            ;d5 = x pixel scroll (0-7).
  300.         and.b    #%111,d4            ;d4 = y pixel scroll (0-7).
  301.         move.l    d5,bg_scroll_x            ;store the scroll values.
  302.         move.l    d4,bg_scroll_y
  303.  
  304.         move.l    bitmap_bg,a0            ;a0 = p0.
  305.         add.l    #(192/8)*16,a0            ;output position fix.
  306.         lea    4224(a0),a3            ;a3 = p1.
  307.  
  308. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  309. ;        copy 176x8 lines
  310. ;        INPUT:
  311. ;        d2    = (background start y) / 8 * 32.
  312. ;        d3    = (background start x) / 8.
  313. ;        a0    = output (p0).
  314. ;        a1    = tiles.
  315. ;        a2    = tile datas.
  316. ;        a3    = output (p1).
  317. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  318.  
  319.         moveq.l    #19-1,d0
  320. qdo_16x8_cdata:    move.l    d2,d7
  321.         or.b    d3,d7
  322.         move.l    d1,d4
  323.         add.b    (a1,d7.l),d4
  324.         lsl.w    #4,d4
  325.         lea    (a2,d4.l),a4
  326.  
  327.         moveq.l    #8-1,d4
  328. so_16x8_cdata:    move.w    (a4)+,d5
  329.         move.w    d5,d6
  330.         lsr.w    #8,d6
  331.  
  332.         move.w    d5,(a3)
  333.         move.w    d6,(a0)
  334.         add.l    #192/8,a3
  335.         add.l    #192/8,a0
  336.         dbra    d4,so_16x8_cdata
  337.  
  338.         add.w    #32,d2
  339.         and.w    #$3ff,d2
  340.         dbra    d0,qdo_16x8_cdata
  341.  
  342.         sub.l    #((192/8)*8*19)-2,a0
  343.         sub.l    #((192/8)*8*19)-2,a3
  344.         addq.b    #1,d3
  345.         and.b    #$1f,d3
  346.         sub.w    #19*32,d2
  347.         and.w    #$3ff,d2
  348.  
  349. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  350. ;        sweeper core
  351. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  352.  
  353.         move.l    #10,x_counter
  354. zdo_16x8_cdata:    moveq.l    #19-1,d0
  355. xdo_16x8_cdata:    move.l    d2,d7
  356.         or.b    d3,d7
  357.         move.l    d1,d4
  358.         add.b    (a1,d7.l),d4
  359.         lsl.w    #4,d4
  360.         addq.b    #1,d3
  361.         lea    (a2,d4.l),a4
  362.         and.b    #$1f,d3
  363.  
  364.         move.l    d2,d7
  365.         or.b    d3,d7
  366.         move.l    d1,d4
  367.         add.b    (a1,d7.l),d4
  368.         lsl.w    #4,d4
  369.         subq.b    #1,d3
  370.         lea    (a2,d4.l),a5
  371.         and.b    #$1f,d3
  372.  
  373.         moveq.l    #8-1,d4
  374. do_16x8_cdata:    move.w    (a4)+,d5
  375.         move.b    d5,d6
  376.         lsl.w    #8,d6
  377.         move.w    (a5)+,d7
  378.         move.b    d7,d6
  379.         lsr.w    #8,d7
  380.         move.b    d7,d5
  381.  
  382.         move.w    d6,(a3)
  383.         move.w    d5,(a0)
  384.         add.l    #192/8,a3
  385.         add.l    #192/8,a0
  386.         dbra    d4,do_16x8_cdata
  387.  
  388.         add.w    #32,d2
  389.         and.w    #$3ff,d2
  390.         dbra    d0,xdo_16x8_cdata
  391.  
  392.         sub.l    #((192/8)*8*19)-2,a0
  393.         sub.l    #((192/8)*8*19)-2,a3
  394.         addq.b    #2,d3
  395.         and.b    #$1f,d3
  396.         sub.w    #19*32,d2
  397.         and.w    #$3ff,d2
  398.  
  399.         subq.l    #1,x_counter
  400.         bne.s    zdo_16x8_cdata
  401.  
  402. xit_cdata:    rts
  403.  
  404. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  405. ;        do the window
  406. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  407.  
  408. screen_draw_wi:    move.l    lcd_control,d0            ;d0 = lcd control byte.
  409.         btst    #5,d0                ;window display?
  410.         beq.s    xit_cdata            ;nope.
  411.         btst    #0,d0
  412.         beq.s    xit_cdata
  413.  
  414.         move.l    gb_memory,a0
  415.         move.l    a0,a2
  416.  
  417.         add.l    #$9800,a0            ;window tiles.
  418.         and.b    #%1000000,d0            ;d0 = tile position.
  419.         lsl.w    #4,d0                ;d0 = 0/1 * 1024.
  420.         add.l    d0,a0                ;a0 = window tiles.
  421.  
  422.         move.l    gb_tiles,a1
  423.  
  424.         add.l    #$ff4a,a2            ;a2 = window y position.
  425.         moveq.l    #0,d0
  426.         move.b    (a2)+,d0            ;d0 = window y pos ($ff4A).
  427.         moveq.l    #0,d1
  428.         move.b    (a2),d1                ;d1 = window x pos ($ff4B).
  429.         cmp.b    #6,d1
  430.         bne.s    win_win_no_no
  431.         addq.l    #1,d1
  432.  
  433. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  434. ;        INPUT:
  435. ;        a0    = window tiles.
  436. ;        a1    = window tile pattern table.
  437. ;        d0    = window y position.
  438. ;        d1    = window x position.
  439. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  440.  
  441. win_win_no_no:    move.l    d0,d6                ;d6 = window y position.
  442.         move.l    d1,d7                ;d7 = window x position.
  443.         lsr.l    #3,d6                ;d6 = y in bytes.
  444.         lsr.l    #3,d7                ;d7 = x in bytes.
  445.  
  446.         add.l    bg_scroll_y,d0
  447.         add.l    #16,d0                ;h/w window y position fix!
  448.         move.w    d0,d2
  449.         lsl.w    #3,d2
  450.         lsl.w    #4,d0
  451.         add.w    d2,d0                ;d0 = d0 * (192/8).
  452.         add.l    bg_scroll_x,d1            ;d1 = x scroll.
  453.         move.l    d1,d2
  454.         lsr.l    #3,d2                ;x = bytes.
  455.         add.l    d2,d0                ;d0 = x and y fixed.
  456.         move.l    d0,a2
  457.         add.l    bitmap_bg,a2            ;a2 = output area (p0).
  458.         and.l    #%111,d1            ;d1 = the inverted shift amount.
  459.         eor.b    #%111,d1            ;d1 = the shift amount.
  460.         lea    4224(a2),a3            ;a3 = output area (p1).
  461.  
  462. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  463. ;        a non transparent h/w window emulator
  464. ;        INPUT:
  465. ;        d0    = x and y added for the start position.
  466. ;        d1    = the shift amount.
  467. ;        d6    = window y position.
  468. ;        d7    = window x position.
  469. ;        a0    = window tiles.
  470. ;        a1    = window tile pattern table.
  471. ;        a2    = output area (p0).
  472. ;        a3    =             (p1).
  473. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  474.  
  475.         subq.l    #1,d7                ;window x correction (h/w).
  476.         move.l    d7,tile_adder_x
  477.         neg.l    d7                ;compute the difference.
  478.         sub.l    #160/8,tile_adder_x
  479.         add.l    #32,tile_adder_x
  480.         add.l    #160/8-1,d7
  481.         blt.w    screen_draw_wxt            ;too much right.
  482.         move.l    d7,win_x
  483.  
  484.         neg.l    d6                ;compute the difference.
  485.         add.l    #144/8-1,d6
  486.         blt.w    screen_draw_wxt            ;too much down.
  487.  
  488.         move.w    #$ff00,d4            ;solid mask.
  489.         rol.w    d1,d4                ;mask shifted.
  490.  
  491. window_loop_y:    move.l    win_x,d7            ;d7 = x-1.
  492.  
  493. copy_8x8:    move.l    tile_adder,d5            ;signum fix.
  494.         add.b    (a0)+,d5            ;d5 = left up tile.
  495.         lsl.w    #4,d5                ;d5 = d5 * 16.
  496.         lea    (a1,d5.l),a6            ;a6 = tile data.
  497.  
  498.         moveq.l    #8-1,d5
  499. copy_8x8_data:    moveq.l    #0,d3
  500.         move.w    (a6)+,d2            ;d2 = L01.
  501.         move.b    d2,d3                ;d3 = xxL1.
  502.         and.w    d4,(a2)
  503.         lsr.w    #8,d2                ;d2 = xxL0.
  504.         and.w    d4,(a3)                ;background masked.
  505.  
  506.         lsl.w    d1,d2                ;p0 shifted.
  507.         or.w    d2,(a2)                ;p0 done.
  508.         lsl.w    d1,d3                ;p1 shifted.
  509.         add.l    #192/8,a2            ;next y (screen).
  510.         or.w    d3,(a3)                ;p1 done.
  511.         add.l    #192/8,a3            ;               .
  512.         dbra    d5,copy_8x8_data        ;next y (register).
  513.  
  514.         sub.l    #(8*192/8)-1,a2            ;next x position.
  515.         sub.l    #(8*192/8)-1,a3            ;               .
  516.         sub.l    #(8*192/8)-1,a4            ;               .
  517.         sub.l    #(8*192/8)-1,a5            ;               .
  518.         dbra    d7,copy_8x8            ;do next 8x8.
  519.  
  520.         add.l    #192/8*8,d0            ;next 192x8 line.
  521.         move.l    d0,a2
  522.         add.l    bitmap_bg,a2            ;a2 = output area (p0).
  523.         lea    4224(a2),a3            ;a3 = output area (p1).
  524.         add.l    tile_adder_x,a0            ;update input position.
  525.         dbra    d6,window_loop_y        ;next y.
  526. screen_draw_wxt:rts
  527.  
  528. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  529. ;        do the sprites
  530. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  531.  
  532. screen_sprites:    move.l    bitmap_spc,a0            ;the sprite area.
  533.         move.l    a0,a1
  534.         add.l    #gb_screen_x/8*gb_screen_y,a1
  535.  
  536. fast_clearing:    move.l    aga_sprs_inactive,a2
  537.         move.w    #gb_screen_y-1,d0
  538.         move.l    #gb_screen_x/8,d2
  539. spr_scnr_empty:    tst.b    (a2)
  540.         bne.s    clear_me
  541.         add.l    d2,a0
  542.         addq.l    #1,a2
  543.         add.l    d2,a1
  544.         dbra    d0,spr_scnr_empty
  545.         bra.s    lines_done
  546. clear_me:    clr.b    (a2)+
  547.         moveq.l    #gb_screen_x/8/4-1,d1
  548. clear_us:    clr.l    (a0)+
  549.         clr.l    (a1)+
  550.         dbra    d1,clear_us
  551.         dbra    d0,spr_scnr_empty
  552.  
  553. lines_done:    move.l    lcd_control,d1            ;d1 = lcd control byte.
  554.         btst    #1,d1                ;sprites off?
  555.         beq.w    spr_exit            ;yes.
  556.  
  557.         move.l    gb_memory,a0
  558.         move.l    a0,a1
  559.         move.l    a0,a2
  560.         add.l    #$fe00+40*4,a0            ;a0 = sprite attribute table.
  561.         add.l    #$8000,a1            ;a1 = sprite pattern table.
  562.         add.l    #$ff48,a2            ;a2 = obj0pal.B, obj1pal.B.
  563.         moveq.l    #40-1,d0            ;d0 = number of sprites.
  564.  
  565.         btst    #2,d1                ;sprite size?
  566.         bne.w    spr_n8x16            ;8x16.
  567.  
  568. spr_n8x8:    move.l    #8-1,sprite_y
  569.         move.l    #8/4-1,sprite_sign
  570.         move.b    #$ff,sprite_mask
  571.         bra.s    spr_c8xq            ;do the copying.
  572. spr_n8x16:    move.l    #16-1,sprite_y
  573.         move.l    #16/4-1,sprite_sign
  574.         move.b    #$fe,sprite_mask
  575.  
  576. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  577. ;        sprite size 8xq, q=8/16.
  578. ;        INPUT:
  579. ;        d0    = number of sprites.
  580. ;        a0    = sprite attribute table.
  581. ;        a1    = sprite pattern table.
  582. ;        a2    = obj0pal.B, obj1pal.B.
  583. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  584.  
  585. spr_c8xq:    move.l    -(a0),d1            ;d1 = y.B, x.B, gfx.B, flags.B.
  586.         move.l    d1,d2
  587.         swap    d2
  588.         tst.b    d2
  589.         beq.w    empty_sprite
  590.         lsr.w    #8,d2
  591.         beq.w    empty_sprite
  592.  
  593. spr_xcute:    swap    d1                ;d1 = gfx.B, flags.B, y.B, x.B.
  594.         move.l    bg_scroll_x,d2            ;x start (bg scroll pixels).
  595.         add.b    d1,d2                ;d2 = x.B.
  596.         cmp.w    #8+160+8,d2            ;out of vision?
  597.         bge.w    spr_xit                ;yes.
  598.  
  599.         move.l    bg_scroll_y,d3            ;y start (bg scroll pixels).
  600.         ror.w    #8,d1                ;d1 = gfx.B, flags.B, x.B, y.B.
  601.         add.b    d1,d3                ;d3 = y.B.
  602.         cmp.w    #16+144+8,d3            ;out of vision?
  603.         bge.w    spr_xit                ;yes.
  604.  
  605.         move.l    aga_sprs_inactive,a6        ;set the marks for clearing.
  606.         add.l    d3,a6
  607.         move.l    sprite_sign,d4
  608. mark_loop:    move.l    #$01010101,(a6)+
  609.         dbra    d4,mark_loop
  610.  
  611.         move.l    sprite_y,d7            ;d7 = y-1.
  612.         move.w    d3,d6
  613.         lsl.w    #3,d6
  614.         lsl.w    #4,d3
  615.         add.w    d6,d3                ;d3 = y on screen.
  616.                             ;(d3 = d3 * 192/8).
  617.         move.l    d2,d4                ;d4 = x.B.
  618.         lsr.w    #3,d4                ;d4 = x.B / 8.
  619.         add.l    d4,d3                ;d3 = y and x fixed.
  620.         move.l    bitmap_spc,a4
  621.         move.l    bitmap_bg,a5
  622.         and.b    #%111,d2            ;d2 = bit skip (0-7).
  623.         add.l    d3,a4                ;a4 = output spr (p0).
  624.         add.l    d3,a5                ;a5 = output bg  (p0).
  625.         rol.l    #8,d1                ;d1 = flags.B, x.B, y.B, gfx.B.
  626.         and.b    sprite_mask,d1
  627.         move.b    d1,d4                ;d4 = gfx.B.
  628.         lsl.w    #4,d4                ;d4 = d4 * 16.
  629.         lea    (a1,d4.l),a6            ;a6 = pattern data.
  630.  
  631.         rol.l    #8,d1                ;d1 = x.B, y.B, gfx.B, flags.B.
  632.         moveq.l    #0,d3
  633.         move.b    d1,d3
  634.         and.b    #%10000,d3            ;palette bit.
  635.         lsr.b    #4,d3                ;take it down.
  636.         ror.l    #8,d1                ;d1 = flags.B, x.B, y.B, gfx.B.
  637.         move.b    (a2,d3.l),d1            ;d1 = flags.B, x.B, y.B, pal.B.
  638.         rol.l    #8,d1                ;d1 = x.B, y.B, pal.B, flags.B.
  639.  
  640.         btst    #6,d1                ;y flipped?
  641.         bne.w    spr_c8xq_flip            ;yes.
  642.  
  643.         btst    #5,d1                ;x flipped?
  644.         bne.s    spr_c8xq_copyx            ;yes.
  645.  
  646. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  647. ;        normal output
  648. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  649.  
  650.         lsr.w    #8,d1                ;d1 = pal.B.
  651. spr_c8xq_copy:    move.w    (a6)+,d3            ;d3 = 01.
  652.         beq.w    next_I
  653.         bsr.w    spr_col_change            ;real colours.
  654.  
  655.         move.b    d3,d4                ;d4 = 01.
  656.         clr.b    d3                ;d3 = 0x.
  657.         lsr.w    d2,d3                ;bits skipped.
  658.         lsl.w    #8,d4                ;d4 = 1x.
  659.         lsr.w    d2,d4                ;bits skipped.
  660.         ror.w    d2,d6                ;d6 = and mask.
  661.  
  662.         and.w    d6,(a4)                ;mask p0.
  663.         or.w    d3,(a4)
  664.         add.l    #4224,a4
  665.         and.w    d6,(a4)                ;mask p1.
  666.         or.w    d4,(a4)
  667.         sub.l    #4224-(192/8),a4        ;next y.
  668.  
  669.         swap    d6                ;adder down.
  670.         swap    d5                ;mask down.
  671.         ror.w    d2,d6                ;adder bits skipped.
  672.         ror.w    d2,d5                ;and mask bits skipped.
  673.         and.w    d5,(a5)
  674.         or.w    d6,(a5)
  675.         add.l    #4224,a5
  676.         and.w    d5,(a5)
  677.         or.w    d6,(a5)
  678.         sub.l    #4224-(192/8),a5
  679.  
  680.         dbra    d7,spr_c8xq_copy        ;next y (register).
  681. spr_xit:    dbra    d0,spr_c8xq            ;next sprite.
  682. spr_exit:    rts
  683.  
  684. next_I:        add.l    #192/8,a4
  685.         add.l    #192/8,a5
  686.         dbra    d7,spr_c8xq_copy        ;next y (register).
  687. empty_sprite:    dbra    d0,spr_c8xq            ;next sprite.
  688.         rts
  689.  
  690. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  691. ;        x flipped output
  692. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  693.  
  694.         cnop    0,4
  695. spr_c8xq_copyx:    lsr.w    #8,d1                ;d1 = pal.B.
  696.  
  697. spr_c8xq_xopyx:    moveq.l    #0,d3
  698.         move.l    x_flip_table,a3
  699.         move.w    (a6)+,d3            ;d3 = 01.
  700.         beq.s    next_II
  701.         move.w    (a3,d3.l*2),d3            ;d3 = x flipped data.
  702.         bsr.w    spr_col_change            ;real colours.
  703.  
  704.         move.b    d3,d4                ;d4 = 01.
  705.         clr.b    d3                ;d3 = 0x.
  706.         lsr.w    d2,d3                ;bits skipped.
  707.         lsl.w    #8,d4                ;d4 = 1x.
  708.         lsr.w    d2,d4                ;bits skipped.
  709.         ror.w    d2,d6                ;d6 = and mask.
  710.  
  711.         and.w    d6,(a4)                ;mask p0.
  712.         or.w    d3,(a4)
  713.         add.l    #4224,a4
  714.         and.w    d6,(a4)                ;mask p1.
  715.         or.w    d4,(a4)
  716.         sub.l    #4224-(192/8),a4        ;next y.
  717.  
  718.         swap    d6                ;adder down.
  719.         swap    d5                ;mask down.
  720.         ror.w    d2,d6                ;adder bits skipped.
  721.         ror.w    d2,d5                ;and mask bits skipped.
  722.         and.w    d5,(a5)
  723.         or.w    d6,(a5)
  724.         add.l    #4224,a5
  725.         and.w    d5,(a5)
  726.         or.w    d6,(a5)
  727.         sub.l    #4224-(192/8),a5
  728.  
  729.         dbra    d7,spr_c8xq_xopyx        ;next y (register).
  730.         dbra    d0,spr_c8xq            ;next sprite.
  731.         rts
  732.  
  733. next_II:    add.l    #192/8,a4
  734.         add.l    #192/8,a5
  735.         dbra    d7,spr_c8xq_xopyx        ;next y (register).
  736.         dbra    d0,spr_c8xq            ;next sprite.
  737.         rts
  738.  
  739. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  740. ;        y flipped output
  741. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  742.  
  743.         cnop    0,4
  744. spr_c8xq_flip:    move.l    d7,d4                ;d4 = y-1.
  745.         addq.b    #1,d4                ;d4 = y.
  746.         lsl.b    #1,d4                ;d4 = y*2.
  747.         add.l    d4,a6                ;y fixed.
  748.  
  749.         btst    #5,d1                ;x flipped?
  750.         bne.s    spr_c8xq_copyxy            ;yes.
  751.  
  752.         lsr.w    #8,d1                ;d1 = pal.B.
  753. spr_c8xq_copyy:    move.w    -(a6),d3            ;d3 = 01.
  754.         beq.s    next_III
  755.         bsr.w    spr_col_change            ;real colours.
  756.  
  757.         move.b    d3,d4                ;d4 = 01.
  758.         clr.b    d3                ;d3 = 0x.
  759.         lsr.w    d2,d3                ;bits skipped.
  760.         lsl.w    #8,d4                ;d4 = 1x.
  761.         lsr.w    d2,d4                ;bits skipped.
  762.         ror.w    d2,d6                ;d6 = and mask.
  763.  
  764.         and.w    d6,(a4)                ;mask p0.
  765.         or.w    d3,(a4)
  766.         add.l    #4224,a4
  767.         and.w    d6,(a4)                ;mask p1.
  768.         or.w    d4,(a4)
  769.         sub.l    #4224-(192/8),a4        ;next y.
  770.  
  771.         swap    d6                ;adder down.
  772.         swap    d5                ;mask down.
  773.         ror.w    d2,d6                ;adder bits skipped.
  774.         ror.w    d2,d5                ;and mask bits skipped.
  775.         and.w    d5,(a5)
  776.         or.w    d6,(a5)
  777.         add.l    #4224,a5
  778.         and.w    d5,(a5)
  779.         or.w    d6,(a5)
  780.         sub.l    #4224-(192/8),a5
  781.  
  782.         dbra    d7,spr_c8xq_copyy        ;next y (register).
  783.         dbra    d0,spr_c8xq            ;next sprite.
  784.         rts
  785.  
  786. next_III:    add.l    #192/8,a4
  787.         add.l    #192/8,a5
  788.         dbra    d7,spr_c8xq_copyy        ;next y (register).
  789.         dbra    d0,spr_c8xq            ;next sprite.
  790.         rts
  791.  
  792. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  793. ;        x and y flipped output
  794. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  795.  
  796.         cnop    0,4
  797. spr_c8xq_copyxy:lsr.w    #8,d1                ;d1 = pal.B.
  798.  
  799. spr_c8xq_xopyxy:moveq.l    #0,d3
  800.         move.l    x_flip_table,a3
  801.         move.w    -(a6),d3            ;d3 = 01.
  802.         beq.s    next_IIII
  803.         move.w    (a3,d3.l*2),d3            ;d3 = x flipped data.
  804.         bsr.b    spr_col_change            ;real colours.
  805.  
  806.         move.b    d3,d4                ;d4 = 01.
  807.         clr.b    d3                ;d3 = 0x.
  808.         lsr.w    d2,d3                ;bits skipped.
  809.         lsl.w    #8,d4                ;d4 = 1x.
  810.         lsr.w    d2,d4                ;bits skipped.
  811.         ror.w    d2,d6                ;d6 = and mask.
  812.  
  813.         and.w    d6,(a4)                ;mask p0.
  814.         or.w    d3,(a4)
  815.         add.l    #4224,a4
  816.         and.w    d6,(a4)                ;mask p1.
  817.         or.w    d4,(a4)
  818.         sub.l    #4224-(192/8),a4        ;next y.
  819.  
  820.         swap    d6                ;adder down.
  821.         swap    d5                ;mask down.
  822.         ror.w    d2,d6                ;adder bits skipped.
  823.         ror.w    d2,d5                ;and mask bits skipped.
  824.         and.w    d5,(a5)
  825.         or.w    d6,(a5)
  826.         add.l    #4224,a5
  827.         and.w    d5,(a5)
  828.         or.w    d6,(a5)
  829.         sub.l    #4224-(192/8),a5
  830.  
  831.         dbra    d7,spr_c8xq_xopyxy        ;next y (register).
  832.         dbra    d0,spr_c8xq            ;next sprite.
  833.         rts
  834.  
  835. next_IIII:    add.l    #192/8,a4
  836.         add.l    #192/8,a5
  837.         dbra    d7,spr_c8xq_xopyxy        ;next y (register).
  838.         dbra    d0,spr_c8xq            ;next sprite.
  839.         rts
  840.  
  841. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  842. ;        change the sprite's colours to the real ones
  843. ;        INPUT:
  844. ;        d1    = palette entries .B.
  845. ;            = xxyyzzcc,
  846. ;              xx = value for colour 3.
  847. ;              yy =                  2.
  848. ;              zz =                  1.
  849. ;              cc =                  0 (processing not required, because
  850. ;                           this is the tranparent colour).
  851. ;        d3    = .W data (p0.B, p1.B).
  852. ;        d4    = available for mutation.
  853. ;        d5    =            .
  854. ;        d6    =            .
  855. ;        OUTPUT:
  856. ;        d3    = .W manipulated data (p0.B, p1.B).
  857. ;        d5    = .W bg p0 and p1 mask, .W rubbish.
  858. ;        d6    = .W bg p0 and p1 adder, .W mask.
  859. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  860.  
  861.         cnop    0,4
  862. spr_col_change:    moveq.l    #8-1,d4                ;this many pixels.
  863.         move.l    #$00ff0000+16-1,d5        ;d5 = mask.W, bit pointer.W.
  864.         move.l    #$000000ff,d6            ;d6 = adder.W, mask.W.
  865.  
  866. spr_col_do:    btst    d4,d3                ;p1 bit test.
  867.         bne.s    spr_col_p0set            ;it's 1!
  868. spr_col_p0clr:    btst    d5,d3                ;p0 bit test.
  869.         bne.s    spr_col_01            ;it's 1!
  870.  
  871. spr_col_00:    bset    d5,d6                ;manipulate the mask.
  872.         swap    d2
  873.         move.b    d5,d2
  874.         swap    d5
  875.         bset    d2,d5
  876.         swap    d5
  877.         swap    d2
  878.         subq.b    #1,d5                ;one down. do no changes.
  879.         dbra    d4,spr_col_do            ;next colour.
  880.         rts                    ;exit.
  881.  
  882.         cnop    0,4
  883. spr_col_01:    btst    #3,d1                ;p0 new colour.
  884.         bne.s    spr_col_01_p01
  885. spr_col_01_p00:    btst    #2,d1                ;p1 new colour.
  886.         bne.s    spr_col_01_p001
  887. spr_col_01_p000:bset    d5,d3
  888.         bclr    d4,d3
  889.         subq.b    #1,d5                ;one down.
  890.         dbra    d4,spr_col_do            ;next colour.
  891.         rts                    ;exit.
  892. spr_col_01_p001:bclr    d5,d3
  893.         bset    d4,d3
  894.         subq.b    #1,d5                ;one down. do no changes.
  895.         dbra    d4,spr_col_do            ;next colour.
  896.         rts                    ;exit.
  897. spr_col_01_p01:    btst    #2,d1                ;p1 new colour.
  898.         bne.s    spr_col_01_p011
  899. spr_col_01_p010:bset    d5,d3
  900.         bset    d4,d3
  901.         subq.b    #1,d5                ;one down.
  902.         dbra    d4,spr_col_do            ;next colour.
  903.         rts                    ;exit.
  904. spr_col_01_p011:bset    d4,d3
  905.         bset    d5,d3
  906.         swap    d6
  907.         bset    d5,d6                ;adder set.
  908.         swap    d6
  909.         subq.b    #1,d5                ;one down. do no changes.
  910.         dbra    d4,spr_col_do            ;next colour.
  911.         rts                    ;exit.
  912.  
  913.         cnop    0,4
  914. spr_col_p0set:    btst    d5,d3                ;p0 bit test.
  915.         bne.s    spr_col_11            ;it's 1!
  916.  
  917. spr_col_10:    btst    #5,d1                ;p0 new colour.
  918.         bne.s    spr_col_10_p01
  919. spr_col_10_p00:    btst    #4,d1                ;p1 new colour.
  920.         bne.s    spr_col_10_p001
  921. spr_col_10_p000:bset    d5,d3
  922.         bclr    d4,d3
  923.         subq.b    #1,d5                ;one down.
  924.         dbra    d4,spr_col_do            ;next colour.
  925.         rts                    ;exit.
  926. spr_col_10_p001:bclr    d5,d3
  927.         bset    d4,d3
  928.         subq.b    #1,d5                ;one down. do no changes.
  929.         dbra    d4,spr_col_do            ;next colour.
  930.         rts                    ;exit.
  931. spr_col_10_p01:    btst    #4,d1                ;p1 new colour.
  932.         bne.s    spr_col_10_p011
  933. spr_col_10_p010:bset    d5,d3
  934.         bset    d4,d3
  935.         subq.b    #1,d5                ;one down.
  936.         dbra    d4,spr_col_do            ;next colour.
  937.         rts                    ;exit.
  938. spr_col_10_p011:bset    d5,d3
  939.         bset    d4,d3
  940.         swap    d6
  941.         bset    d5,d6                ;adder set.
  942.         swap    d6
  943.         subq.b    #1,d5                ;one down. do no changes.
  944.         dbra    d4,spr_col_do            ;next colour.
  945.         rts                    ;exit.
  946.  
  947.         cnop    0,4
  948. spr_col_11:    btst    #7,d1                ;p0 new colour.
  949.         bne.s    spr_col_11_p01
  950. spr_col_11_p00:    btst    #6,d1                ;p1 new colour.
  951.         bne.s    spr_col_11_p001
  952. spr_col_11_p000:bset    d5,d3
  953.         bclr    d4,d3
  954.         subq.b    #1,d5                ;one down.
  955.         dbra    d4,spr_col_do            ;next colour.
  956.         rts                    ;exit.
  957. spr_col_11_p001:bclr    d5,d3
  958.         bset    d4,d3
  959.         subq.b    #1,d5                ;one down. do no changes.
  960.         dbra    d4,spr_col_do            ;next colour.
  961.         rts                    ;exit.
  962. spr_col_11_p01:    btst    #6,d1                ;p1 new colour.
  963.         bne.s    spr_col_11_p011
  964. spr_col_11_p010:bset    d5,d3
  965.         bset    d4,d3
  966.         subq.b    #1,d5                ;one down.
  967.         dbra    d4,spr_col_do            ;next colour.
  968.         rts                    ;exit.
  969. spr_col_11_p011:bset    d5,d3
  970.         bset    d4,d3
  971.         swap    d6
  972.         bset    d5,d6                ;adder set.
  973.         swap    d6
  974.         subq.b    #1,d5                ;one down. do no changes.
  975.         dbra    d4,spr_col_do            ;next colour.
  976.         rts                    ;exit.
  977.  
  978. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  979. ;        output the created view
  980. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  981.  
  982. screen_draw_pl:    cmp.b    #1,old_render            ;render mode?
  983.         beq.w    screen_screen            ;screen!
  984.  
  985.         bsr.b    read_pixels_and_scale
  986.  
  987.         bra.w    output_the_data
  988.  
  989. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  990. ;        read pixels and scale the data if scaling is needed
  991. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  992.  
  993. read_pixels_and_scale:
  994.         moveq.l    #0,d0
  995.         moveq.l    #0,d1
  996.         move.l    #159,d2
  997.         move.l    #143,d3
  998.  
  999.         tst.b    old_refresh            ;mode 144/144?
  1000.         beq.s    no_shifting            ;yes.
  1001.  
  1002. shifted_blit:    move.l    #8,d4                ;area x fix.
  1003.         move.l    #16,d5                ;area y fix.
  1004.         add.l    bg_scroll_x,d4            ;src x.
  1005.         add.l    bg_scroll_y,d5            ;src y.
  1006.         add.l    d4,d0
  1007.         add.l    d4,d2
  1008.         add.l    d5,d1
  1009.         add.l    d5,d3
  1010.  
  1011. no_shifting:    cmp.b    #1,old_render
  1012.         bne.s    no_cyber_screen_read
  1013.  
  1014.         move.l    game_tmp_rast_port,a1
  1015.         move.l    gb_rport_I,a0
  1016.         bra.s    read_pixels_a_lot
  1017.  
  1018. no_cyber_screen_read:
  1019.         move.l    game_rast_port,a0
  1020.         move.l    game_tmp_rast_port,a1
  1021.  
  1022. read_pixels_a_lot:
  1023.         move.l    graphics_base,a6
  1024.         move.l    game_array,a2
  1025.         jsr    ReadPixelArray8(a6)
  1026.  
  1027. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1028. ;        scaling
  1029. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1030.  
  1031.         cmp.b    #1,old_render            ;render mode?
  1032.         beq.w    cyber_screen_data_exit        ;screen!
  1033.  
  1034.         tst.b    scaling_status
  1035.         beq.w    no_data_scaling
  1036.  
  1037.         move.l    game_array,a0
  1038.         move.l    game_scale_array,a1
  1039.         move.l    wzonka_game_x,d0
  1040.         move.l    wzonka_game_y,d1
  1041.  
  1042.         cmp.w    #320,d0
  1043.         beq.w    scaling_320xb
  1044.  
  1045.         bsr.w    convert_array_pens
  1046.  
  1047. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1048. ;        scaling (a x b)
  1049. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1050.  
  1051. scaling_axb:    move.l    #160*256,d2
  1052.         move.l    #144*256,d3
  1053.         divu.l    d0,d2
  1054.         divu.l    d1,d3
  1055.         move.w    d0,d4
  1056.         subq.w    #1,d4
  1057.         move.w    d1,d5
  1058.         subq.w    #1,d5
  1059.         moveq.l    #0,d7
  1060.  
  1061. compute_scaling_y:
  1062.         move.w    d4,d6
  1063.         moveq.l    #0,d0
  1064.         move.l    d7,d1
  1065.         lsr.l    #8,d1
  1066.         mulu.w    #160,d1
  1067.         lea    (a0,d1.l),a4
  1068. compute_scaling_x:
  1069.         move.l    d0,d1
  1070.         lsr.l    #8,d1
  1071.         move.b    (a4,d1.l),(a1)+
  1072.         add.l    d2,d0
  1073.         dbra    d6,compute_scaling_x
  1074. scale_the_image_next_line:
  1075.         add.l    d3,d7
  1076.         dbra    d5,compute_scaling_y
  1077.         bra.w    data_scaling_exit
  1078.  
  1079. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1080. ;        scaling (320 x b)
  1081. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1082.  
  1083. scaling_320xb:    cmp.w    #144,d1
  1084.         beq.w    scaling_320x144
  1085.         cmp.w    #288,d1
  1086.         beq.w    scaling_320x288
  1087.  
  1088.         move.l    #144*256,d3
  1089.         divu.l    d1,d3
  1090.         move.w    d1,d5
  1091.         subq.w    #1,d5
  1092.         moveq.l    #0,d7
  1093.         move.l    pen_conversion_table,a6
  1094.  
  1095. compute_scaling_320_y:
  1096.         moveq.l    #160/2-1,d6
  1097.         move.l    d7,d1
  1098.         lsr.l    #8,d1
  1099.         mulu.w    #160,d1
  1100.         lea    (a0,d1.l),a4
  1101. compute_scaling_320_x:
  1102.         moveq.l    #0,d0
  1103.         move.w    (a4)+,d0
  1104.         move.w    (a6,d0.l*2),d0
  1105.         lsl.l    #8,d0
  1106.         lsr.w    #8,d0
  1107.         move.l    d0,d1
  1108.         lsl.l    #8,d0
  1109.         or.l    d1,d0
  1110.         move.l    d0,(a1)+
  1111.         dbra    d6,compute_scaling_320_x
  1112. scale_the_image_next_line_320:
  1113.         add.l    d3,d7
  1114.         dbra    d5,compute_scaling_320_y
  1115.         bra.w    data_scaling_exit
  1116.  
  1117. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1118. ;        scaling (320 x 144)
  1119. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1120.  
  1121. scaling_320x144:subq.w    #1,d1
  1122.         move.l    pen_conversion_table,a6
  1123.  
  1124. compute_scaling_320x144_y:
  1125.         moveq.l    #160/2-1,d6
  1126. compute_scaling_320x144_x:
  1127.         moveq.l    #0,d0
  1128.         move.w    (a0)+,d0
  1129.         move.w    (a6,d0.l*2),d0
  1130.         lsl.l    #8,d0
  1131.         lsr.w    #8,d0
  1132.         move.l    d0,d2
  1133.         lsl.l    #8,d0
  1134.         or.l    d2,d0
  1135.         move.l    d0,(a1)+
  1136.         dbra    d6,compute_scaling_320x144_x
  1137. scale_the_image_next_line_320x144:
  1138.         dbra    d1,compute_scaling_320x144_y
  1139.         bra.w    data_scaling_exit
  1140.  
  1141. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1142. ;        scaling (320 x 288)
  1143. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1144.  
  1145. scaling_320x288:move.w    #144-1,d1
  1146.         move.l    pen_conversion_table,a6
  1147.  
  1148. compute_scaling_320x288_y:
  1149.         moveq.l    #160/2-1,d6
  1150. compute_scaling_320x288_x:
  1151.         moveq.l    #0,d0
  1152.         move.w    (a0)+,d0
  1153.         move.w    (a6,d0.l*2),d0
  1154.         lsl.l    #8,d0
  1155.         lsr.w    #8,d0
  1156.         move.l    d0,d2
  1157.         lsl.l    #8,d0
  1158.         or.l    d2,d0
  1159.         move.l    d0,(a1)
  1160.         move.l    d0,320(a1)
  1161.         addq.l    #4,a1
  1162.         dbra    d6,compute_scaling_320x288_x
  1163. scale_the_image_next_line_320x288:
  1164.         add.l    #320,a1
  1165.         dbra    d1,compute_scaling_320x288_y
  1166.  
  1167. data_scaling_exit:
  1168.         move.l    game_scale_array,a2
  1169.         move.l    wzonka_game_x,d2
  1170.         move.l    wzonka_game_y,d3
  1171.         subq.w    #1,d2
  1172.         subq.w    #1,d3
  1173.         rts
  1174.  
  1175. no_data_scaling:bsr.w    convert_array_pens
  1176.         move.l    game_array,a2
  1177.         move.l    #159,d2
  1178.         move.l    #143,d3
  1179.         rts
  1180.  
  1181. cyber_screen_data_exit:
  1182.         move.l    game_array,a2
  1183.         move.l    #159,d2
  1184.         move.l    #143,d3
  1185.         rts
  1186.  
  1187. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1188. ;        output the data
  1189. ;        INPUT:
  1190. ;        d2    = output x.
  1191. ;        d3    =        y.
  1192. ;        a2    = input array.
  1193. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1194.  
  1195. output_the_data:move.l    wzonka_ptr,a0
  1196.         move.l    wd_RPort(a0),a0
  1197.  
  1198. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1199. ;        output the data - rest
  1200. ;        INPUT:
  1201. ;        d2    = output x.
  1202. ;        d3    =        y.
  1203. ;        a0    = output rastport.
  1204. ;        a2    = input array.
  1205. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1206.  
  1207. output_the_data_rest:
  1208.         moveq.l    #0,d0
  1209.         moveq.l    #0,d1
  1210.  
  1211.         cmp.l    #FALSE,output_cyber_status
  1212.         beq.s    no_cyber_routines
  1213.  
  1214.         tst.l    cyber_base
  1215.         bne.s    use_cyber_routines
  1216.  
  1217. no_cyber_routines:
  1218.         move.l    graphics_base,a6
  1219.         move.l    game_output_tmp_rast_port,a1
  1220.         jsr    WritePixelArray8(a6)
  1221.         rts
  1222.  
  1223. use_cyber_routines:
  1224.         move.l    cyber_base,a6
  1225.         move.l    a0,a1
  1226.         addq.w    #1,d2
  1227.         addq.w    #1,d3
  1228.         move.w    d2,d5
  1229.         move.w    d3,d6
  1230.         move.l    a2,a0
  1231.         moveq.l    #0,d3
  1232.         moveq.l    #0,d4
  1233.         move.l    #RECTFMT_LUT8,d7
  1234.         jsr    WritePixelArray(a6)
  1235.         rts
  1236.  
  1237. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1238. ;        convert array pens
  1239. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1240.  
  1241.         cnop    0,4
  1242. convert_array_pens:
  1243.         move.l    game_array,a3
  1244.         move.l    pen_conversion_table,a4
  1245.         move.w    #160*144/2/8-1,d6
  1246.         moveq.l    #0,d7
  1247. convert_array:    move.w    (a3),d7
  1248.         move.w    (a4,d7.l*2),(a3)+
  1249.         move.w    (a3),d7
  1250.         move.w    (a4,d7.l*2),(a3)+
  1251.         move.w    (a3),d7
  1252.         move.w    (a4,d7.l*2),(a3)+
  1253.         move.w    (a3),d7
  1254.         move.w    (a4,d7.l*2),(a3)+
  1255.         move.w    (a3),d7
  1256.         move.w    (a4,d7.l*2),(a3)+
  1257.         move.w    (a3),d7
  1258.         move.w    (a4,d7.l*2),(a3)+
  1259.         move.w    (a3),d7
  1260.         move.w    (a4,d7.l*2),(a3)+
  1261.         move.w    (a3),d7
  1262.         move.w    (a4,d7.l*2),(a3)+
  1263.         dbra    d6,convert_array
  1264.         rts
  1265.  
  1266. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1267. ;        output a screen
  1268. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1269.  
  1270. screen_screen:    tst.l    cyber_base
  1271.         bne.w    cyber_screen
  1272.  
  1273.         tst.b    gb_buffer_no
  1274.         bne.s    zscreen_II
  1275.  
  1276. zscreen_I:    move.l    gb_bmap_I,a2
  1277.         move.b    #1,gb_buffer_no
  1278.         move.l    gb_bmap_II,a0
  1279.         bra.s    zscreen
  1280.  
  1281. zscreen_II:    move.l    gb_bmap_II,a2
  1282.         clr.b    gb_buffer_no
  1283.         move.l    gb_bmap_I,a0
  1284.  
  1285. zscreen:    lea    bm_Planes(a0),a0        ;to bitmaps.
  1286.         move.l    (a0),bitmap_bg
  1287.         move.l    8(a0),bitmap_spc
  1288.  
  1289.         move.l    gb_screen_ptr,a0
  1290.         lea    sc_ViewPort(a0),a0
  1291.         move.l    vp_RasInfo(a0),a1
  1292.  
  1293.         move.w    bg_scroll_x+2,d0
  1294.         add.w    #8,d0
  1295.         move.w    bg_scroll_y+2,d1
  1296.         add.w    #16,d1
  1297.  
  1298.         tst.b    old_refresh            ;mode 144/144?
  1299.         bne.s    use_these_values
  1300.  
  1301.         moveq.l    #0,d0
  1302.         moveq.l    #0,d1
  1303.  
  1304. use_these_values:
  1305.         move.w    d0,ri_RxOffset(a1)
  1306.         move.w    d1,ri_RyOffset(a1)
  1307.         move.l    a2,ri_BitMap(a1)
  1308.  
  1309.         move.l    graphics_base,a6
  1310.         jsr    ScrollVPort(a6)
  1311.  
  1312.         tst.b    os_screen_speed_limit
  1313.         beq.s    no_speed_limit
  1314.  
  1315.         jsr    WaitTOF(a6)
  1316.  
  1317. no_speed_limit:    rts
  1318.  
  1319. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1320. ;        cybergraphics screen
  1321. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  1322.  
  1323. cyber_screen:    bsr.w    read_pixels_and_scale
  1324.  
  1325.         move.l    gb_screen_ptr,a0        ;the screen.
  1326.         lea    sc_RastPort(a0),a0
  1327.         bra.w    output_the_data_rest
  1328.